Sometimes it is nice not to display the whole category tree for your
menu without having to deactivate the categories. The below patch
(against the current 1.4rc1 svn) allows you to use something like the
following in your template file to display only two levels down
(including the top most level).
For example in /default/template/catalog/navigation/top.phtml
change
<?php echo $this->drawItem($_category) ?>
to
<?php echo $this->drawItem($_category,null,null,2) ?>
Please let me know if you come across any issues.
Kristof@Fooman
Index: app/code/core/Mage/Catalog/Block/Navigation.php
===================================================================
--- app/code/core/Mage/Catalog/Block/Navigation.php (revision 61498)
+++ app/code/core/Mage/Catalog/Block/Navigation.php (working copy)
@@ -171,17 +171,18 @@
}
/**
- * Enter description here...
+ * Create orderered list/menu from category tree
*
* @param Mage_Catalog_Model_Category $category
* @param int $level
* @param boolean $last
+ * @param string|int $drawLevels
* @return string
*/
- public function drawItem($category, $level=0, $last=false)
+ public function drawItem($category, $level=0, $last=false,
$drawLevels='all')
{
$html = '';
- if (!$category->getIsActive()) {
+ if (!$category->getIsActive() || $drawLevels<=0) {
return $html;
}
if (Mage::helper('catalog/category_flat')->isEnabled()) {
@@ -226,7 +227,7 @@
$htmlChildren = '';
foreach ($children as $child) {
if ($child->getIsActive()) {
- $htmlChildren.= $this->drawItem($child, $level+1,
++$j >= $cnt);
+ $htmlChildren.= $this->drawItem($child, $level+1,
++$j >= $cnt,$drawLevels=='all'?'all':$drawLevels-1);
}
}
in System > Configuration > Catalog > Category Top Navigation there is an option to limit the category navigation depth.
Isn't that the same?
Vinai
> --
> You received this message because you are subscribed to the Google Groups "Magento Development List" group.
> To post to this group, send email to magent...@googlegroups.com.
> To unsubscribe from this group, send email to magento-deve...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/magento-devel?hl=en.
>
yes, for the probably not well chosen use case I gave, this would come
to the same. Thanks for pointing that out. I am currently using it to
display the top category menu twice - one with all possible
subcategories and one restricted to show only 1 level deep. I believe
the menu item Category Navigation Depth only works against the root
category for the store. With the patch you should be able to turn any
category into a menu/list with the option to limit its depth as
required.
Cheers
Kristof